package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"context"
	"house_srv/house"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseAddLogic) HouseAdd(req *types.HouseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.HouseRpc.HouseAdd(l.ctx, &house.HouseAddRequest{
		Title:    req.Title,
		Image:    req.Image,
		Address:  req.Address,
		UserId:   req.UserId,
		MinPrice: float32(req.MinPrice),
		MaxPrice: float32(req.MaxPrice),
		Price:    float32(req.Price),
		Size:     req.Size,
	})

	if err != nil {
		return &types.Response{
			Mes:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Mes:  "房源发布成功",
		Code: 200,
		Data: add,
	}, nil
}
